<style>
    #febs-project xm-select {
        min-height: 30px;
        line-height: 30px;
    }
    #febs-project xm-select > .xm-label .scroll .label-content {
        display: flex;
        padding: 0 30px 0 10px;
    }
</style>
<div class="layui-fluid layui-anim febs-anim" id="febs-project" lay-title="项目管理">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="user-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">关键词</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="title" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">状态</label>
                                        <div class="layui-input-inline">
                                            <select name="state">
                                                <option value=""></option>
                                                <option value="1">未审核</option>
                                                <option value="2">未通过</option>
                                                <option value="3">已通过</option>
                                                <option value="5">已完成</option>
                                                <option value="6">未完成</option>
                                                <option value="7">资金发放中</option>
                                                <option value="8">项目失败</option>
                                                <option value="9">已关闭</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">类型</label>
                                        <div class="layui-input-inline">
                                            <select name="type">
                                                <option value=""></option>
                                                <option value="1">游戏</option>
                                                <option value="2">动漫</option>
                                                <option value="3">出版</option>
                                                <option value="4">桌游</option>
                                                <option value="5">活动</option>
                                                <option value="6">音乐</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="userTable" lay-data="{id: 'userTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="project-status">
    {{#
    let status = {
    1: {title: '未审核', color: 'magenta'},
    2: {title: '未通过', color: 'red'},
    3: {title: '已通过', color: 'green'},
    5: {title: '已完成', color: 'blue'},
    6: {title: '未完成', color: 'gold'},
    7: {title: '资金发放中', color: 'cyan'},
    8: {title: '项目失败', color: 'red'},
    9: {title: '已关闭', color: 'orange'}
    }[d.state];
    }}
    <span class="layui-badge febs-bg-{{status.color}}">{{ status.title }}</span>
</script>
<script type="text/html" id="project-type">
    {{#
    let type = {
    6: {title: '音乐'},
    5: {title: '活动'},
    4: {title: '桌游'},
    3: {title: '出版'},
    2: {title: '动漫'},
    1: {title: '游戏'}
    }[d.type];
    }}
    <span>{{ type.title }}</span>
</script>
<script type="text/html" id="project-option">
<!--    <span shiro:lacksPermission="user:view,user:update,user:delete">-->
<!--        <span class="layui-badge-dot febs-bg-orange"></span> 无权限-->
<!--    </span>-->
{{#  if(d.state === 1){ }}
    <a lay-event="edit" ><span class="layui-badge febs-bg-blue}">提交审核</span></a>
{{#  }else{ }}
<span class="layui-badge febs-bg-green">已审核</span>
{{#  } }}
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'laydate', 'form', 'table', 'febs', 'xmSelect'], function () {
        let $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            $view = $('#febs-project'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'title', type: null},
            tableIns;

        form.render();

        initTable();

        table.on('tool(userTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'edit') {

                febs.modal.info('提示',"提交审核前，请先查看项目详情",function () {
                    febs.modal.open('审核', 'system/project/exam/'+data.projectId, {
                        area: $(window).width() <= 750 ? '90%' : '50%',
                        btn: ['确认', '取消'],
                        yes: function (index, layero) {
                            $('#febs-project-exam').find("#submit").trigger("click");
                        },
                        btn2: function () {

                            layer.closeAll();
                        }
                    });
                });

            }
        });

        table.on('sort(userTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'userTable',
                url: ctx + 'project/list',
                cols: [[
                    {field: 'title', title: '标题', minWidth: 100},
                    {field: 'shortTitle', title: '短标题', minWidth: 100},
                    {title: '类型',templet: '#project-type'},
                    {field: 'goal', title: '目标金额'},
                    {field: 'introduce', title: '简介', minWidth: 180},
                    {title: '开始时间', minWidth: 120,templet: function (data) {
                            return layui.util.toDateString(data.fundBegin, 'yyyy-MM-dd')
                        }},
                    {title: '结束时间', minWidth: 120,templet: function (data) {
                            return layui.util.toDateString(data.fundEnd, 'yyyy-MM-dd')
                        }},
                    {title: '状态', templet: '#project-status'},
                    {title: '详情', minWidth: 120,templet: function(data){
                            return "<a href=/web/admin/project_preView?projectId="+data.projectId+" target='_blank'>"+"点我查看"+"</a>"
                        }},
                    {title: '操作', toolbar: '#project-option', minWidth: 140}
                ]],
                height: "500px"
            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            params.invalidate_ie_cache = new Date();
            return params;
        }

        function deleteUsers(userIds) {
            let currentUserId = currentUser.userId + '';
            if (('' + userIds).split(',').indexOf(currentUserId) !== -1) {
                febs.alert.warn('所选用户包含当前登录用户，无法删除');
                return;
            }
            febs.get(ctx + 'user/delete/' + userIds, null, function () {
                febs.alert.success('删除用户成功');
                $query.click();
            });
        }

        function getAllNode(Node) {
            // 获取当前节点下全部得子节点的id
            var arr = new Array();
            deepChild(Node,arr);
            return arr;

        }

        function deepChild(Node,arr) {
            arr.push(Node.data.deptId);
            if (Node.hasChild) {
                for (let i = 0; i < Node.children.length; i++) {
                    let child = Node.children[i];
                    if (child.hasChild) {
                        deepChild(child, arr);
                    } else {
                        arr.push(child.data.deptId);
                    }
                }
            }
        }
    })
</script>